<?php
namespace app\common\only\tyyh;

class User extends Base {
	protected $prefix = 'tyyh\\User';

	//通过用户名查找用户信息
	public function find4username($username) {
		$model = $this->getModel();
		return $this->get('find4username', function($model, $username) {
			return $model->where('username', $username)->find();
		}, [$model, $username]);
	}

	//通过用户名查找用户信息
	public function unionid4username($username) {
		return $this->get('unionid4username', function($only, $username) {
			$model = $only->getModel('tyyh\\UserOpenid');
			$row = $only->find4username($username);
			if(empty($row)) {
				return '';
			}
			$row = $model->where(['uid' => $row['id']])->find();
			return $row['unionid'];
		}, [$this, $username]);
	}
}
